<!-- Content unit - One column -->
<div class="column1-unit">
	<div class="contactform" style="border:none;background:none;">
		<!--  -->
		<form id="personal-info" method="post" action="/diastole/patient/savepersonalinfo/<?php echo $id_patient;?>">
				<input type="hidden" id="patient_id" name="id" value="<?php echo $id_patient; ?>"/>
		
				<p>
					<label for="surname" class="left">Apellido:</label>
					<input type="text" name="surname" id="surname" class="field" value="<?php echo $patient->getSurname();?>" tabindex="1" />
				</p>
				<p>
					<label for="name" class="left">Nombre:</label> 
					<input type="text" name="name" id="name" class="field" value="<?php echo $patient->getName();?>" tabindex="2" />
				</p>
			
				<p>
					<label for="sex" class="left">Sexo:</label>
					<input type="radio" name="sex" id="male"  value="Masculino" tabindex="3" <?php if ($patient->getGenre() == "M") echo 'checked="checked"'; ?>/><label style="margin-left:2px;margin-right:2em;">Masculino</label>
					<input type="radio" name="sex" id="female" value="Femenino" tabindex="4" <?php if ($patient->getGenre() == "F") echo 'checked="checked"';?>/><label style="margin-left:2px;margin-right:2em;">Femenino</label>
				</p>
			
				<p>
					<label for="doctype" class="left">Tipo de Documento:</label> 
					<select	name="doctype" id="doctype" class="combo">
						<option value="0">Seleccione...</option>
						<?php
							$patient_doctype = $patient->getDoctype();
							foreach($doctypes as $doctype){
						?>
							<option value="<?php echo $doctype->id; ?>" <?php if ($patient_doctype->id == $doctype->id) echo 'selected="selected"';?>>
								<?php echo $doctype->description; ?>
							</option>	
						<?php 		
							} 
						?>
						
					</select>
				</p>
				<p>
					<label for="identity_card_number" class="left">N° de Documento:</label> 
					<input type="text" name="identity_card_number" id="identity_card_number" class="field" value="<?php echo $patient->getIdentityCardNumber();?>" tabindex="5" />
				</p>
				
				<p>
					<label for="birthdate" class="left">Fecha de Nacimiento:</label> 
					<input type="text" name="birthdate" id="birthdate" class="field" value="<?php echo $patient->getBirthdate(); ?>" tabindex="6" />
				</p>
				
				<p>
					<label for="age" class="left">Edad:</label> 
					<input type="text" name="age" id="age" class="field" value="<?php echo $patient->getAge();?>" tabindex="7" />
				</p>
								
				<p>
					<label for="profession" class="left">Profesi&oacute;n:</label> 
					<select	name="profession" id="profession" class="combo">
						<option value="0">Seleccione...</option>
						<?php
							$patient_profession = $patient->getProfession();
							foreach($professions as $profession){
						?>
							<option value="<?php echo $profession->id; ?>" <?php if ($patient_profession->id == $profession->id) echo 'selected="selected"';?>>
								<?php echo $profession->profession; ?>
							</option>	
						<?php 		
							} 
						?>
					</select>
				</p>
				
				<p>
					<label for="email" class="left">Email:</label> 
					<input type="text" name="email" id="email" class="field" value="<?php echo $patient->getEmail(); ?>" tabindex="8" />
				</p>
				
				<p>
					<label for="cellphone" class="left">Celular:</label> 
					<input type="text" name="cel" id="cellphone" class="field" value="<?php echo $patient->getCellphone(); ?>" tabindex="9" />
				</p>
				
				<p>
					<label for="phone" class="left">Tel&eacute;fono:</label> 
					<input type="text" name="phone" id="phone" class="field" value="<?php echo $patient->getPhone(); ?>" tabindex="10" />
				</p>
				
				
				<p>
					<label for="address" class="left">Direcci&oacute;n:</label> 
					<input type="text" name="address" id="address" class="field" value="<?php echo $patient->getAddress(); ?>" tabindex="11" />
				</p>
				
				<p>
					<label for="city" class="left">Localidad:</label> 
					<input type="text" name="city" id="city" class="field" value="<?php echo $patient->getCity(); ?>" tabindex="12" />
				</p>
			
				<!--  <p>
					<label for="contact_message" class="left">Message:</label> 
					<textarea name="contact_message" id="contact_message" cols="45" rows="10" tabindex="5"></textarea>
				</p>-->
				<p>
					<input type="button" name="submit" id="submit" class="button" value="Guardar" tabindex="13" />
					<input type="reset" name="reset" id="reset" class="button" value="Cancelar" tabindex="14" />
				</p>
		</form>
	</div>
</div>
<script type="text/javascript" src="media/js/js_controls/js_date.js"></script>
<script type="text/javascript">
	//validar datos de entrada (por lo menos los campos requeridos)
	//realizar submit ajax y mostrar un cartel de datos guardados ->escenario exitoso
	//mostrar error o valores incorrectos
	
	var PersonalInfoWidget = (function(){
		return {
	
			init : function(birthdate){
				var that = this;
				DateControl.createDatePicker("#birthdate",birthdate,"Regressive");
				$j("#birthdate").change(function(){
					that.calculateAge(this.value);
					return false;
				});

				$j("#age").change(function(){
					that.calculateBirthdate(this.value);
					return false;
				});
				
				$j("#reset").click(PatientWidget.backToList);
				$j("#submit").click(this.sendData);
			},
			calculateAge : function(birthdate){
				$j("#age").val(DateControl.determineAge(birthdate));
				return;
			},
			calculateBirthdate : function(age){
				$j("#birthdate").val(DateControl.determineBirthdate(age));
				return;
			},		
			sendData : function(){
				var url = $j("#personal-info").attr("action");
				//var data = $("#personal-info :input[value][value!='.']").serializeArray();
				
				var data = $j("#personal-info :input").serializeArray();
				var json = {};
				jQuery.map(data, function(n, i){
					json[n['name']] = n['value'];
				});

				$j.post(url,json,function(response){
					var inserted_id = response;
					if (!PatientWidget.isEditing()){
						$j("#patient_id").val(inserted_id);
						PatientWidget.updatePatientHeader($j("#surname").val() + ", " + $j("#name").val());
						PatientWidget.enableActions(inserted_id);
						PatientWidget.setEditing(true);
					}
				});
			}
		};
	}());
	PersonalInfoWidget.init("<?php echo $patient->getBirthdate();?>"); 
</script>